//
//  Building.cpp
//  宿舍管理系统
//
//  Created by 孟强定 on 2020/6/26.
//  Copyright © 2020 mqd. All rights reserved.
//

#include "Building.hpp"

Building::Building(int n):num(n){
    floors = new Floor[n];
}
void Building::init(int buildingId){
    this->buildingId=buildingId;
    for(int i=0;i<num;i++)
        floors[i].init(buildingId,i+1);
}
void Building::autoDistribute(int building){
    for(int i=0;i<num;i++){
        floors[i].autoDistribute();
    }
}
bool Building::autoDistributeOne(Student* stu){
    if (!stu) return 0;
    for(int i=0;i<num;i++){
        if (floors[i].autoDistributeOne(stu)) return 1;
    }
    return 0;
}

bool Building::manualDistributeOne(Student *stu, int floorId, int roomId){
    if (!stu) return 0;
    if (floorId<0 || floorId>=num) return 0;
    return floors[floorId].manualDistributeOne(stu, roomId);
}
bool Building::find(int floor, int room){
    if (floor<0 || floor>=num) return 0;
    return floors[floor].find(room);
}

bool Building::delOne(Student *stu){
    if (!stu) return 0;
    return floors[stu->getFloorId()-1].delOne(stu);
}
